<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ include file="/view/common/init.jsp"%>
<title>Thêm role</title>
<script type="text/javascript">
function submitEditRoleForm(){
	if (!check('role.roleName', 'Tên role', null, 40)){
		return false;
	}
	new Ajax.Request(base_url + 'role/nameIsUsed.do?role.roleName=' + $('role.roleName').value, {
		method : 'post',
		onSuccess : function(transport) {
			var data = transport.responseText.evalJSON();
			// Init Countries combo
			if (data.nameIsUsed=='false'){
				$('editRoleForm').submit();
			} else {
				alert('Tên role đã tồn tại! Hãy chọn lại');
				setTimeout(function(){$('role.roleName').focus();}, 10);		
			}
		},
		onFailure : function() {
			alert('Something went wrong...');
		}
	});		
	 	
}
</script>
<center>
<div class="header">THÊM ROLE</div>
<div style="width: 980px;">
<s:form action="addComplete.do" id="editRoleForm">
<table class="tbl_info" border="0" width="613">
	<tbody>
		<tr>
			<td class="hed" colspan="2" />THÊM ROLE</td>
		</tr>
		<tr><td>Tên role<span class="error">&nbsp;*</span></td>
		<td>
			<s:textfield name="role.roleName" 
				cssClass="require" id="role.roleName"/>	
		</td></tr>
</tbody>
</table>
<div style="margin-top: 30px;">
	<button type="button" onclick="history.back();">Hủy bỏ</button>
	<button type="button" onclick="submitEditRoleForm();">Đồng ý</button>
</div>
</s:form>
</div>
</center>